/**
 * mxt 2016.12.28
 */

import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
} from 'react-native';

export default class Button extends Component {
    constructor(props) {
        super(props);
        this.state = {
            disabled: false,
        };
    }

    onPress = () => {
        //自定义的方法 使用属性来定义
        const {onPress}= this.props;
        this.disable();
        onPress(this.enable);
    };
    enable = () => {

        this.setState({
            disabled: false,
        });
    };
    disable = () => {
        this.setState({
            disabled: true,
        });
    };
    render() {
        const { text, beijing }= this.props;
        return (
            <View style={[styles.container,]}>
                <TouchableOpacity style={[styles.button,,{backgroundColor:this.props.beijing},this.state.disabled && styles.disable]}
                                  disabeld={this.state.disabled}
                                  onPress={this.onPress}>
                    <Text style={styles.buttonText}>{this.props.text}</Text>
                </TouchableOpacity>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    button:{
        backgroundColor:'green',
        height:40,
        width:100,
        borderRadius:20,
        justifyContent:'center',
    },
    buttonText:{
        textAlign:'center',
        color:'white'
    },
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
    },
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
    },
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
    },
    disable:{
        backgroundColor:'gray',
    },
});

